package com.ermao.learnWebmagic.config;

import com.ermao.learnWebmagic.entity.Video;

import java.lang.reflect.Field;
import java.util.ArrayList;

public class Config {
	/**
	 * 要抓取的 UP 主的数量
	 */
	public static final int UP_NUMS = 20;

	/**
	 * 对于每个 UP 主，需要抓取的视频的个数
	 */
	public static final int UP_VIDEO_NUMS = 30;

	/**
	 * user-agent
	 */
	public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36";

	/**
	 * 线程休眠时间
	 */
	public static final Integer SLEEP_TIME = 1000;

	/**
	 * 重试次数
	 */
	public static final Integer RETRY_TIMES = 3;

	/**
	 * 线程数量
	 */
	public static final Integer THREAD_NUM = 5;

	/**
	 * 附件 key
	 */
	public static final String EXTRA = "extra";

	/**
	 * UP 文件存储位置
	 */
	public static final String UP_CSV_FILE = "up.csv";

	/**
	 * Video 文件存储位置
	 */
	public static final String VIDEO_CSV_FILE_NAME = "data.csv";

	/**
	 * Video 文件存储 headers
	 */
	public static final String[] VIDEO_CSV_FILE_HEADER =
			{"video_up_mid", "video_title", "video_play", "video_created", "video_like", "video_coin"
					, "video_fav", "video_share", "video_reply", "video_danmaku", "video_tags"};

	/**
	 * Video 文件存储 headers
	 */
	public static final String[] UP_CSV_FILE_HEADER = {"up_name", "mid", "followers"};



	public static String[] csvHeaders() {
		ArrayList<String> list = new ArrayList<>(10);
		Class<Video> clazz = Video.class;
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			field.setAccessible(true);
			list.add(field.getName());
		}
		return list.toArray(new String[0]);
	}

}
